package com.mnxc.gxa.controller;


import com.mnxc.gxa.dto.QueryRoleDTO;
import com.mnxc.gxa.dto.Result;
import com.mnxc.gxa.entity.Role;
import com.mnxc.gxa.entity.User;
import com.mnxc.gxa.service.IRoleService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiResponse;
import io.swagger.annotations.ApiResponses;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author mnxc
 * @since 2023-06-29
 */
@RestController
@RequestMapping("/role")
@Api(tags = "角色相关接口")
public class RoleController {
    @Resource
    IRoleService roleService;
    @GetMapping("/getAll")
    @ApiOperation(value = "获取角色接口",notes = "获取所有角色",httpMethod = "GET",produces = "application/json;charset=utf-8")
    @ApiResponses({
            @ApiResponse(code=1,message="请求成功"),
            @ApiResponse(code=404,message="找不到页面"),
            @ApiResponse(code=0,message="后台服务错误")
    })
    public Result getAll(){
        return roleService.getAll();
    }
    @PostMapping
    @ApiOperation(value = "新增角色接口",notes = "新增角色",httpMethod = "POST",produces = "application/json;charset=utf-8")
    @ApiResponses({
            @ApiResponse(code=1,message="请求成功"),
            @ApiResponse(code=404,message="找不到页面"),
            @ApiResponse(code=0,message="后台服务错误")
    })
    public Result saveRole(@RequestBody  Role role){
        return roleService.saveRole(role);

    }
    @GetMapping
    @ApiOperation(value = "分页查询接口",notes = "查询信息",httpMethod = "GET",produces = "application/json;charset=utf-8")
    @ApiResponses({
            @ApiResponse(code=1,message="请求成功"),
            @ApiResponse(code=404,message="找不到页面"),
            @ApiResponse(code=0,message="后台服务错误")
    })
    public Result getByPageAndCondition(Integer page, Integer pageSize, QueryRoleDTO query){
        return roleService.getByPageAndCondition(page,pageSize,query);
    }
    @DeleteMapping
    @ApiOperation(value = "删除角色接口",notes = "删除角色",httpMethod = "DELETE",produces = "application/json;charset=utf-8")
    @ApiResponses({
            @ApiResponse(code=1,message="请求成功"),
            @ApiResponse(code=404,message="找不到页面"),
            @ApiResponse(code=0,message="后台服务错误")
    })
    public Result deleteRole(Role role){
        return roleService.deleteRole(role);
    }
    @PutMapping
    @ApiOperation(value = "修改角色接口",notes = "修改角色的信息",httpMethod = "PUT",produces = "application/json;charset=utf-8")
    @ApiResponses({
            @ApiResponse(code=1,message="请求成功"),
            @ApiResponse(code=404,message="找不到页面"),
            @ApiResponse(code=0,message="后台服务错误")
    })
    public Result updateRole(@RequestBody Role role){
        return roleService.updateRole(role);
    }
    @PutMapping("/freeze")
    @ApiOperation(value = "冻结角色的接口",notes = "冻结角色",httpMethod = "PUT",produces = "application/json;charset=utf-8")
    @ApiResponses({
            @ApiResponse(code=1,message="请求成功"),
            @ApiResponse(code=404,message="找不到页面"),
            @ApiResponse(code=0,message="后台服务错误")
    })
    public Result freezeRole(@RequestBody Role role){
        return roleService.freezeRole(role);
    }
    @PutMapping("/active")
    @ApiOperation(value = "激活角色接口",notes = "激活角色",httpMethod = "PUT",produces = "application/json;charset=utf-8")
    @ApiResponses({
            @ApiResponse(code=1,message="请求成功"),
            @ApiResponse(code=404,message="找不到页面"),
            @ApiResponse(code=0,message="后台服务错误")
    })
    public Result activeRole(@RequestBody Role role){
        return roleService.activeRole(role);
    }
    @GetMapping("/mulDelete/{ids}")
    public Result mulDeleteRole(@PathVariable List<Long> ids){
        return roleService.mulDeleteRole(ids);
    }
    @GetMapping("/mulActive/{ids}")
    public Result mulActiveRole(@PathVariable List<Long> ids){
        return roleService.mulActiveRole(ids);
    }
    @GetMapping("/mulFreeze/{ids}")
    public Result mulFreezeRole(@PathVariable List<Long> ids){
        return roleService.mulFreezeRole(ids);
    }
}


